package deep.projects.newsapp.activities;

import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import deep.projects.newsapp.R;

/**
 * @author 吾心无待 于2016年03月05日
 */
public class NewsDetailActivity extends BaseLayoutActivity {
    private ProgressDialog mProgressDialog;
    private int mNewsID;//新闻ID
    private int mNewsTypeID;//新闻类型ID
    private String mUrl;//新闻链接 URL

    @BindView(R.id.wv_news) WebView mWebView;//webview
    @BindView(R.id.tv_comment) TextView mtvComment;//评论
    @BindView(R.id.iv_share) ImageView mivShare;//新闻分享
    @Override
    public int getLayoutId() {
        return R.layout.activity_news_detail;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        tvTitle.setText(R.string.title_activity_news_detail);
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setMessage("正在拼命加载...");
        WebSettings ws = mWebView.getSettings();
        ws.setSupportZoom(false);//支持缩放
        ws.setDefaultTextEncodingName("UTF-8");//设置默认编码UTF-8
        ws.setDefaultFontSize(16);
        ws.setBuiltInZoomControls(false);
        ws.setJavaScriptEnabled(true);
        ws.setJavaScriptCanOpenWindowsAutomatically(true);
        ws.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                mProgressDialog.show();
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                mProgressDialog.dismiss();
                super.onPageFinished(view, url);
            }
        });
        mNewsID = getIntent().getIntExtra("NewsId",0);
        mNewsTypeID = getIntent().getIntExtra("NewsTypeId", 0);
        mUrl = getIntent().getStringExtra("Url");
        Log.i(TAG,mUrl);
        mWebView.loadUrl(mUrl);
    }


}
